// pages/index/community_style/community_style.js
import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
import Dialog from "../../../miniprogram_npm/@vant/weapp/dialog/dialog"
const app = getApp()
const log = new app.appLogs()
const http = new app.appHttp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    theme: {},
    list: [],
    pageNumber: 1,
    pageSize: 10,
    isRefresh: true,
    isLoading: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "社区风采"
    })
    this.setData({
      theme: app.globalData.theme
    })
    this.getStyleList()
  },

  /**
   * 获取社区风采列表
   */
  getStyleList: function () {
    this.setData({
      isLoading: true
    })
    http.get("notice/open/page",{
      type: 4,
      applet_id:app.globalData.applet_id,
      page_number: this.data.pageNumber,
      page_size: this.data.pageSize,
      unit_code: app.globalData.unitCode,
    }).then(res => {
      if (res.data.code === http.REQUEST_OK) {
        res.data.data.list.forEach(item => {
          this.data.list.push(item)
        })
        this.setData({
          list: this.data.list,
          isRefresh: false,
          isLoading: false
        })
      }else {
        Dialog.alert({
          title: "失败",
          message: "获取失败\n" + res.data.msg
        }).then(() => {

        })
        this.setData({
          isRefresh: false,
          isLoading: false
        })
      }
    }, err => {
      Toast.fail("网络异常")
      this.setData({
        isRefresh: false,
        isLoading: false
      })
    })
  },

  /**
   * 下拉刷新
   * @param e
   */
  onRefresh: function (e) {
    this.data.pageNumber = 1
    this.data.list = []
    this.getStyleList()
  },

  /**
   * 上拉加载更多
   * @param e
   */
  onLower: function (e) {
    this.data.pageNumber += 1
    this.getStyleList()
  },

  /**
   * 社区风采详情
   * @param e
   */
  onStyleDetail: function (e) {
    const id = e.currentTarget.dataset.id
    const content_id = e.currentTarget.dataset.content_id
    wx.navigateTo({
      url: "./detail/detail?id=" + id + "&content_id=" + content_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})